package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.simpleframework.xml.Path;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * ClassName: CategoryController
 * Package: com.atguigu.spzx.manager.controller
 * Description:
 *
 * @Author 刘强
 * @Create 2024/7/4 14:48
 * @Version 1.0
 */
@Tag(name = "分类管理")
@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {
    @Resource
    private CategoryService categoryService;

    @GetMapping("findAll")


    /**
     * 导入分类的excel文件
     * @param file
     * @return
     */
    @PostMapping("importData")
    public Result importData(MultipartFile file){
        categoryService.importData(file);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 分类excel的下载
     */
    @GetMapping("exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }

    /**
     * 根据id查询子分类列表
     * @param parentId
     * @return
     */
    @Operation(summary = "根据id查询子分类列表")
    @GetMapping("findByParentId/{parentId}")
    public Result findByParentId(@PathVariable Long parentId){
        List<Category> list = categoryService.findByParentId(parentId);
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }
}
